<template>
  <div>
    <ul class="mui-table-view">
      <li class="mui-table-view-cell mui-media" v-for="item in newsList" >
        <a  @click="clickNewsInfo(item.id)">
          <img class="mui-media-object mui-pull-left" :src="item.img_url">
          <div class="mui-media-body">
            <h1>{{item.title}}</h1>
            <p class='mui-ellipsis'>
              <span>发表时间:{{item.add_time | dateFormat('YYYY-MM-DD')}}</span>
              <span>点击:{{item.click}}次</span>
            </p>
          </div>
        </a>
      </li>

    </ul>

  </div>
</template>

<script>
  import {Toast} from 'mint-ui'
  export default {
      data(){
          return{
              newsList:[]
          }
      },
      methods:{
          getNewsList(){
              this.$http.get('/api/news/getnewslist').then(res => {
                  if(res.body.success ===true) {
                    this.newsList = res.body.page.list;
                  }else {
                    Toast("加载新闻列表失败！！！")
                  }
              });
          },
          clickNewsInfo(id) {//点击详情时，点击次数+1
              this.$http.post("/api/news/updateOneNewsClick?id="+id).then(res => {
                  if(res.body.size<=0) {
                      Toast("点击加载失败")
                  }else {
                      this.$router.push('/home/newsinfo/'+id);
                  }
              })
          }
      },
      created() {
          this.getNewsList()
      }
  }

</script>


<style lang="scss" scoped>
  .mui-table-view{
    li{
      h1{
        font-size: 14px;
      }
      .mui-ellipsis{
        font-size: 12px;
        color: #226aff;
        display: flex;
        justify-content: space-between;
      }
    }

  }

</style>
